<template>
  <div class="content-container">
    <div class="map-full-screen-btn" @click="mapFullscreen" ></div>
    <div class="contents">
      <div v-if="!isMapFullScreen" class="contetn_left">
        <ItemWrap 
          class="contetn_left-top contetn_lr-item" 
          title="测站统计"  
          style="padding: 0 10px 16px 10px">
          <LeftTop/>
        </ItemWrap>
        <ItemWrap 
          class="contetn_left-center contetn_lr-item" 
          title="报警信息" 
          rightText="历史数据"
          source="WarnHistoryTable"
          @search-history="searchHistory"
          style="padding: 0 10px 16px 10px">
          <LeftCenter />
        </ItemWrap>
        <ItemWrap
          class="contetn_left-bottom contetn_lr-item"
          title="取水计划"
          rightText="历史数据"
          source="WaterIntakePlan"
          @search-history="searchHistory"
          style="padding: 0 10px 16px 10px">
          <LeftBottom />
        </ItemWrap>
      </div>
      <div :class="{'contetn_center': !isMapFullScreen, 'contetn_center_full': isMapFullScreen}" id="contetn_center">
        <ul class="station-list">
          <li class="active">全县</li>
          <li>区域1</li>
          <li>区域2</li>
          <li>区域3</li>
          <li>区域4</li>
          <li>区域5</li>
        </ul>
        <CenterMap :style="{flex: isMapFullScreen ? 1 : ''}" class="contetn_center_top"/>
        <div v-if="!isMapFullScreen" class="contetn_lr-item">
          <ItemWrap
            class="contetn_lr-item"
            title="水位变化趋势 ">
            <CenterBottom />
          </ItemWrap>
        </div>
        
      </div>
      <div v-if="!isMapFullScreen" class="contetn_right">
        <ItemWrap
          class="contetn_left-bottom  contetn_lr-item-2"
          rightText="历史数据"
          source="WaterIntakeStatistic"
          @search-history="searchHistory"
          title="取水统计">
          <div class="contetn_left-bottom contetn_lr-item">
            <RightTop/>
          </div>
          <div class="contetn_left-bottom contetn_lr-item" style="padding: 0 10px 16px 10px; margin-top:20px;">
            <RightCenter  />
          </div>
        </ItemWrap>
        <ItemWrap
          class="contetn_left-bottom contetn_lr-item"
          title="本月用水统计 ">
          <RightBottom />
        </ItemWrap>
      </div>
    </div>
    
    <CustomDialog
      :dialogVisible="dialogVisible"
      :fullscreen="fullscreen">
      <ItemWrap
        :title="dialogTittle "
        :height="fullscreen ? '100%' : '500px'"
        width="624px"
        :type="1"
        backgroundColor="rgba(1, 20, 48, 1)">
        <template v-slot:RightIcon>
          <!-- el-icon-copy-document -->
            <span :class="[fullscreen ? 'el-icon-copy-document' : 'el-icon-full-screen', 'full-screen']" @click="isFullscreen"></span>
            <span class="el-icon-close close-btn" @click="handleClosed"></span>
        </template>
        <component :is="currentComponents" :table-height="tableHeight"></component>
      </ItemWrap>
    </CustomDialog>
  </div>
</template>

<script>
import CenterMap from "../../components/map/center-map.vue";
import LeftTop from './left-top.vue'
import LeftCenter from "./left-center.vue";
import LeftBottom from "./left-bottom.vue";
import CenterBottom from "./center-bottom.vue";
import RightTop from "./right-top.vue";
import RightCenter from "./right-center.vue";
import RightBottom from "./right-bottom.vue";
import BottomCenterLeftTop from "./bottom-center-left-top.vue";
import BottomCenterLeftBottom from "./bottom-center-left-bottom.vue";
import WarnHistoryTable from "./warn-history-table.vue";
import WaterIntakePlan from "./water-intake-plan.vue";
import WaterIntakeStatistic from "./water-intake-statistic.vue";

export default {
  components: {
    LeftTop,
    LeftCenter,
    LeftBottom,
    CenterMap,
    RightTop,
    RightCenter,
    RightBottom,
    CenterBottom,
    BottomCenterLeftTop,
    BottomCenterLeftBottom,
    WarnHistoryTable,
    WaterIntakePlan,
    WaterIntakeStatistic
  },
  data() {
    return {
      dialogTittle: '报警历史数据',
      dialogVisible: false,
      fullscreen: false,
      currentComponents: 'WarnHistoryTable',
      tableHeight: 380,
      tableKey: 1,
      dialogTable: {
        WarnHistoryTable: 350,
        WaterIntakePlan: 380
      },
      isMapFullScreen: false
    };
  },

  filters: {
    numsFilter(msg) {
      return msg || 0;
    },
  },

  created() {

  },

  watch: {
    fullscreen() {
        if (this.fullscreen) {
            this.changeHeight()
        } else {
            this.tableHeight = this.dialogTable[this.currentComponents];
        }
    }
  },

  methods: {
    searchHistory(type, rightText) {
      this.fullscreen = false;
      this.currentComponents = type;
      this.dialogVisible = true;
      this.dialogTittle = rightText;
      this.tableHeight = this.dialogTable[this.currentComponents];
    },

    isFullscreen() {
      this.fullscreen = !this.fullscreen;
    },

    mapFullscreen() {
      this.isMapFullScreen = !this.isMapFullScreen;
    },

    handleClosed() {
      this.dialogVisible = false;
    },

    changeHeight() {
        this.$nextTick(() => {
            this.getTableHeight()
        });
    },

    getTableHeight() {
      const h = window.innerHeight;
      this.tableHeight = h - 30;
      // 首次加载强制更新table组件
      if (this.tableKey === 1) this.tableKey++;
    },
  },
};
</script>
<style lang="scss" scoped>
.content-container{
  width: 100%;
  height: 100%;
}
// 内容
.contents {
  width: 100%;
  height: 100%;
  .contetn_left,
  .contetn_right {
    width: 540px;
    box-sizing: border-box;
    padding-bottom: 90px;
  }

  .contetn_center {
    width: 780px;
    padding-bottom: 90px;
    flex: 1;
    margin: 0 15px;
  }

  #contetn_center {
    .station-list {
      z-index: 9999;
      top:20px;
      margin-left: 10px;
      position: absolute;
      li {
        cursor: pointer;
        font-size: 12px;
        margin: 0 10px;
        display: inline-block;
        padding: 4px 10px;
        color: rgb(2, 167, 240);
        border: 1px solid rgb(2, 167, 240);
        border-radius: 5px;
      }
      .active {
        background-image: inherit;
        background-position: inherit;
        background-size: inherit;
        background-repeat: inherit;
        background-attachment: inherit;
        background-origin: inherit;
        background-clip: inherit;
        background-color: rgb(22, 155, 213);
        border: none;
        border-radius: 5px;
        box-shadow: none;
        color: #fff;
        
      }

    }
  }

  .contetn_center_full {
    width: 780px;
    flex: 1;
    padding-bottom: 90px;
  }

  //左右两侧 三个块
  .contetn_lr-item {
    height: 300px;
  }

  .contetn_lr-item-2 {
    height: 620px !important;
  }

  .contetn_center_top {
    width: 100%;
    height: 620px;
    // flex: 1;
    // position: absolute;
    // left: 0;
    // top: 0;
  }

  // 中间
  .contetn_center {
    display: flex;
    flex-direction: column;
    justify-content: space-around;
    position: relative;
  }

  .contetn_center_full {
    display: flex;
    flex-direction: column;
    justify-content: space-around;
    position: relative;
  }

  .contetn_center-bottom {
    display: flex;
    flex-direction: row;
    justify-content: space-around;
    height: 300px;
   
  }

  .contetn_center-bottom-left {
    width: 400px
  }

  .contetn_center-bottom-right {
    width: 400px
  }

  //左边 右边 结构一样
  .contetn_left,
  .contetn_right {
    display: flex;
    flex-direction: column;
    justify-content: space-around;
    position: relative;
  }
}

.full-screen {
  color: #fff;
  font-weight: 600;
  font-size: 16px;
  margin-right: 12px;
  z-index: 99999;
}

.close-btn {
  color: #fff;
  font-weight: 600;
  font-size: 18px;
  cursor: pointer;
  z-index: 99999;
}

.map-full-screen-btn {
  cursor: pointer;
  position: absolute;
  left: 14px;
  top: 65px;
  width: 26px;
  height: 24px;
  z-index: 999;
  background: url('../../assets/img/toggle.svg') center center no-repeat;
  color: #fff;
}

</style>
